package com.iwhalecloud.citybrain.flow.platform.manager;

import java.io.IOException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.env.EnvironmentPostProcessor;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.PropertySource;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.DefaultPropertySourceFactory;
import org.springframework.core.io.support.EncodedResource;

/**
 * @author lilh
 * @date 2021/1/4 下午1:48
 */
public class DefaultPropertySourceEnvironmentPostProcessor implements EnvironmentPostProcessor {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Override
    public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
        Resource resource = new DefaultResourceLoader().getResource("classpath:flow-default.properties");
        try {
            PropertySource<?> propertySource = new DefaultPropertySourceFactory().createPropertySource("flow-default-property", new EncodedResource(resource, "utf-8"));
            environment.getPropertySources().addLast(propertySource);
        } catch (IOException e) {
            logger.error("加载flow-default.properties文件失败");
        }
    }
}
